<template>
    <div v-if="loading" style="height:100vh;background:#F8F8F8;">
        <van-nav-bar
        title="我的信息"
        left-text="返回"
        left-arrow
        @click-left="$router.back(-1)"
        />

        <div class="user_bg">
            <div class="user_info">
                <div class="icon_box">
                    <img src="../../assets/user_icon2.png"/>
                </div>
                <div class="user_name">{{ userInfo.u_user }}</div>
            </div>
        </div>

        <van-cell-group style="margin-top:20rem">
            <van-cell :title="'账户余额：'+userInfo.u_money" is-link ></van-cell>
            <van-cell @click="exit_login" title="退出登录" is-link />
        </van-cell-group>
    </div>
</template>

<script>
export default {
    data(){
        return {
            userInfo:{},
            loading: false
        }
    },
    methods:{
        getUser(){

          let that =this

          let toast1 = this.$toast.loading({
              message:'加载中...',
              duration: 0,
              forbidclick: true
          })

          this.$axios.post('/login/check_login',this.$qs.stringify({type:1})).then( (res) => {

              if(res.data.code==1){
                  
                  that.loading = true

                  that.userInfo = res.data.data

                  toast1.clear()
              }else{

                  if(res.data.code==-1){

                      that.$toast.fail('您还未登录~')

                      that.$router.push({path:'/login'})
                  }else{
                      that.$router.push({path:'/'})

                      that.$toast.fail(res.data.msg)
                  }

              }

          } ).catch( (err) => {

              that.$toast.fail('网络繁忙~')

              that.$router.push({path:'/'})
          } )
      },
      exit_login(){
          this.$dialog.confirm({
  title: '退出提示',
  message: '确定要退出登录吗？',
})
  .then(() => {
    
    let that = this

    let toast1 = this.$toast.loading({
              message:'操作中...',
              duration: 0,
              forbidclick: true
          })

    this.$axios.post('/login/exit').then( (res) => {

        if(res.data.code==1){

            that.$toast.success('操作成功~')

            that.$router.push({path:'/'})

        }else{

            that.$toast.fail(res.data.msg)

        }

    } ).catch( (err) => {
        
        that.$toast.fail('网络繁忙~')

    } )
  })
  
  .catch(() => {
    // on cancel
  });

      }
    },
    created(){
        this.getUser()
    }
}
</script>

<style scoped>
    .user_bg{
        width:750rem;
        height: 320rem;
        background: url('../../assets/userbg.jpg');
        background-size: cover;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .user_bg .user_info .icon_box{
        width:100rem;
        height: 100rem;
        background-color: #fff;
        border-radius: 100rem;
        overflow: hidden;
    }
    .user_bg .user_info .icon_box img{
        width:100rem;
        height: 100rem;
    }
    .user_bg .user_info .user_name{
        font-size: 30rem;
        color:#fff;
        margin-top:20rem;
    }
</style>